package org.delphy.indy2.controls
{
	import flash.events.MouseEvent;
	import flash.filters.BevelFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextLineMetrics;
	
	import org.delphy.indy2.controls.carbonTextInputClasses.CarbonMagnifyButton;
	import org.delphy.indy2.containers.CarbonMagnifyWindow;
	
	public class CarbonMagnifyTextInput extends CarbonTextInput
	{
		
		private var magButton:CarbonMagnifyButton;
		
		[Embed(source="org/delphy/indy2/assets/images/magnify.png")]
		private var magIcon:Class;
		
		private var _showIcon:Boolean=false;
		
		[Bindable]
		public function get showIcon():Boolean{
			return _showIcon;
		}
		public function set showIcon(value:Boolean):void{
			if(value!=_showIcon){
				_showIcon=value;
				invalidateDisplayList();
			}
		}
		
		private var _label:String;

		public function get label():String
		{ 
			return _label; 
		}

		public function set label(value:String):void
		{
			if (value !== _label)
			{
				_label = value;
				magButton.label=value;
				invalidateDisplayList();
			}
		}
		
		public function CarbonMagnifyTextInput()
		{
			super();
			
			styleName="carbonMagnifyTextInput";
			
			magButton=new CarbonMagnifyButton();
			magButton.addEventListener(MouseEvent.CLICK,onMagnifyClick);
			
		}
		
		override protected function createChildren():void{
			super.createChildren();
			
			addChild(magButton);
		}
		
		override protected function commitProperties():void{
			super.commitProperties();
			
			magButton.label=_label;
		}
		
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight);

			
			magButton.label=label;
			magButton.width=magButton.measuredWidth+10;
			magButton.height=unscaledHeight-5;
			
			magButton.x=3;
			magButton.y=3;
							
			setStyle("paddingLeft",magButton.x+magButton.width);
		}

		private function onMagnifyClick(evt:MouseEvent):void{
			if(text!=""){
				var magWindow:CarbonMagnifyWindow=new CarbonMagnifyWindow();
				magWindow.text=text;
				magWindow.popUp();
			}
		}
		
	}
}